import {fhirSearchApi, fhirHistoryApi, fhirDeleteApi} from "../../api/modules/fhirApi";
import {createMedicationApi, updateMedicationApi} from "../../api/modules/medicationApi";

export default {
  state: {
    medications: []
  },
  mutations: {
    setMedications(state, data) {
      state.medications = data;
    }
  },
  actions: {
    getMedicationList({commit, rootState}, params) {
      return fhirSearchApi(params).then(res => {
        console.log(res);
        commit('setMedications', res.data.entry ? res.data.entry : [{resource: res.data}])
      }).catch(res => {
        commit('setMedications', []);
      })
    },
    getHistoryMedicationList({commit, rootState}, params) {
      return fhirHistoryApi(params).then(res => {
        commit('setMedications', res.data.entry ? res.data.entry : [{resource: res.data}])
      })
    },
    updateMedication({commit, rootState}, params) {
      return updateMedicationApi(params);
    },
    createMedication({commit, rootState}, params) {
      return createMedicationApi(params);
    },
    deleteMedication({commit, rootState}, params) {
      return fhirDeleteApi(params);
    }
  }
}
